#!/bin/sh
#copy latest netcare-agent
sudo scp -r  $2@$1:$3/netcare/linux_64/netcare-agent /usr/bin/
#write init
echo "#!/bin/sh
#chkconfig: 235 98 01
### BEGIN INIT INFO
# provides              netcare_init
# Required-Start:	$"network" $"remote_fs" haldaemon
# Should-Start:		
# Required-Stop:	$"network" $"remote_fs" haldaemon
# Should-Stop:		
# Default-Start:	2 3 5
# Default-Stop:	
# description:          netcare
### END INIT INFO
start(){ 
/usr/bin/netcare-agent &
echo  "service Netcare is started..."  
}     
stop(){   
killall netcare-agent
echo  "service Netcare is stoped..."  
}  
  
case $"1" in   
start)   
start   
;;   
stop)   
stop   
;;   
*)   
echo "error choice ! please input start or stop";;   
esac   
exit 0" > /etc/init.d/netcare-agent
chmod +x /etc/init.d/netcare-agent #add netcare to run

#create connect in different run level
sudo chkconfig --add netcare-agent

#start netcare
sudo cp /root/Documents/netcare/netcare_version /usr/bin/
sudo service netcare-agent start &
sudo sed -i '9i\-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 55555 -j ACCEPT' /etc/sysconfig/iptables
sudo service iptables restart

exit 1
